\chapter{Methodology}
\label{ch:method}
In this chapter it is explained how RSSI and LQI values will be obtained from the motes, how the values will be analyzed. Furthermore it is discussed how the LQI and RSSI values obtained can be used for localization. 

\section{Study of the RSSI and LQI values}

\subsection{Overall view of the setup}
The setup used for colecting RSSI and LQI values is based on the TinyOS RSSI Demo tutorial\cite{TinyOsRssiDemo}. The tutorial software is capable of collecting RSSI values as it is. The modified software used has been extended to collect LQI values as well,

There are two types of motes in the setup, one Base mote and possibly several Sender motes. The Base mote is used to collect data from the Sender motes. This is accomplished by letting the sender motes send empty packages with room for RSSI and LQI values to the base station. On reception, the base mote is able to detect the RSSI and LQI values, and it will copy the values to the package before sending it to the host machine through a serial connection. 

In all our tests, we use the default transmission power for the CC2420,\\ CC2420\_DEF\_RFPOWER\ $=31$, which corresponds to maximum power\cite{CC2420}. Refer to Appendix~\ref{appendixA} for figures of software component wirings.

\subsection{The Base Station}
The base station acts as a bridge between the base station's radio and UART communication. This functionality is implemented in the BaseStationC component, which provides an intercept message which we use to fill in the packet with RSSI and LQI values. These values are obtained with the tranceiver IC specific CC2420ActiveMessageC component. 

\subsection{The Sender Mote}
When properly booted, the Sending mote begins sending packages to the Base Station periodically with an interval of 250 milliseconds. The ActiveMessageC component is used, so that the packet includes sender and receiver addresses as well as packet type.

\subsubsection{The logging application}
The logging application is written in java. Through a serial connection it will receive data forwarded by the Base station. The application has been modified, so that it will print a line each time a message is receiced, until it has received 20 messages, after which it will exit.

\subsubsection{Analysis of results}
In our tests the Base station is set to a fixed position. The mote with Sender Mote software is our \emph{moving node}. When the wanted distance between the base station mote and the moving mote has been set, 20 values for the given distance is recorded, and after that the moving note is placed at another distance. We redirect the output from the logging application to a file, calculate the average for each point and plot the data. Furthermore we develop a model using the pass loss equation. 

Tests for reading RSSI and LQI values will are performed in three different environments: inside in a corridor at IHA, outside on a playing field, and in the radio dead room at IHA. In all three environments TelosB motes are used as Base station and moving notes. For comparison a test in the radio dead room using a ASEBAN mote as the moving note is performed.

The tests and their results are presented in section \ref{ch:experiments}.

\section{Localization}
Here we first briefly describe different stategies for using signal strength values for localization purposes.

\begin{description}
\item{Trilateration} In three-dimentional trilateration, a point is is located using three distances $d_1, d_2, d_3$. One can imagine three spheres with radii equal to $d_1, d_2, d_3$. The point to be localized is where the three spheres intersect. In practice, the spheres seldomly intersect in a point, and optimization wrt. error distance must be applied.
\item{Triangulation} In triangulation, instead of using distances, three angles are used to calculate a point. Considering two dimensions, if two angles are known, the third can easily be calculated, as can its position. This can be generalized to three dimensions as well. 
\item{Fingerprinting} With fingerprinting, a radio map is constructed by measuring RSSI at points spread over the are in which localization is needed. When a position of a note is to be determined, its RSSI is compared with the radio map. The comparison can be done in different ways \cite{Bahl00radar:an}, with different demands on the number of known anchors.
\item{Wall Attenuation Factor} In this model, the number of walls in the way from sender to receiver is taken into account. From  \cite{Bahl00radar:an}, the wall attenuation factor model is described by
\begin{equation}
P(s) [\textrm{dBm}] = P(d_0) [\textrm{dBm}] - 10 n \log\left(\frac{d}{d_0}\right) - \left\{
	\begin{array}{rll}
		nW \times W\!AF & \textrm{for} & nW < C \\
		C \times W\!AF & & nW \ge{} C
	\end{array}
\right.
\end{equation}	
where $n$ indicates the rate at which the path loss
increases with distance, $P(d_0)$ is the signal power at some
reference distance $d_0$ and $d$ is the transmitter-receiver (T-R)
separation distance. $C$ is the maximum number of
obstructions (walls) up to which the attenuation factor makes
a difference, $nW$ is the number of obstructions (walls)
between the transmitter and the receiver, and $W\!AF$ is the wall
attenuation factor.
\end{description}

We use trilateration in that we regard the RSSI values as a measure for the distance between sender and receiver motes. For our localization experiments we use three Sender motes as anchor notes. We will use a fourth mote as moving mote, and take a number RSSI readings relative to the anchor motes. We use the path loss model developed for the open space environment, as the localization experiments will be carried out in a similar environment. For determining the theoretical RSSI value taking all three anchor motes into account, we use Cramer's rule. In our analysis we calculate errors, i.e the distance between the threoretical value and the calculated position using the RSSI values obtained, and present an error plot.
